﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => CONV_USER
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 11:52:49
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DataAccess.Interface;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;

#endregion

namespace DataAccess.Dal
{
    internal class ConvUserDal //: IResponsible<Prop.ConvUser>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static ConvUserDal _dal;

        private System.String sql = "";


        public static ConvUserDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new ConvUserDal();

            return _dal;
        }

        public IEnumerable<Prop.ConvUser> Select(Prop.ConvUser obj)
        {
            IEnumerable<Prop.ConvUser> entities = new List<Prop.ConvUser>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.EMPNO))
                    {
                        concast.Append(" AND EMPNO=:EMPNO ");
                        hashtable.Add(":EMPNO", obj.EMPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.EMPNO6))
                    {
                        concast.Append(" AND EMPNO6=:EMPNO6 ");
                        hashtable.Add(":EMPNO6", obj.EMPNO6);
                    }

                    if (!String.IsNullOrEmpty(obj.ADNO))
                    {
                        concast.Append(" AND ADNO=:ADNO ");
                        hashtable.Add(":ADNO", obj.ADNO);
                    }

                    if (!String.IsNullOrEmpty(obj.USRNAME))
                    {
                        concast.Append(" AND USRNAME=:USRNAME ");
                        hashtable.Add(":USRNAME", obj.USRNAME);
                    }

                }
                sql = System.String.Format(@" SELECT EMPNO ,EMPNO6 ,ADNO ,USRNAME  FROM CONV_USER");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.ConvUser>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public Boolean Add(Prop.ConvUser obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO CONV_USER(EMPNO ,EMPNO6 ,ADNO ,USRNAME )
					VALUES(:EMPNO ,:EMPNO6 ,:ADNO ,:USRNAME ");

                hashtable = new Hashtable();
                hashtable.Add(":EMPNO", obj.EMPNO);
                hashtable.Add(":EMPNO6", obj.EMPNO6);
                hashtable.Add(":ADNO", obj.ADNO);
                hashtable.Add(":USRNAME", obj.USRNAME);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Update(Prop.ConvUser obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE CONV_USER
					SET
					EMPNO=:EMPNO,
					EMPNO6=:EMPNO6,
					ADNO=:ADNO,
					USRNAME=:USRNAME");

                hashtable = new Hashtable();
                hashtable.Add(":EMPNO", obj.EMPNO);
                hashtable.Add(":EMPNO6", obj.EMPNO6);
                hashtable.Add(":ADNO", obj.ADNO);
                hashtable.Add(":USRNAME", obj.USRNAME);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Delete(Prop.ConvUser obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.EMPNO))
                    {
                        concast.Append(" AND EMPNO=:EMPNO ");
                        hashtable.Add(":EMPNO", obj.EMPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.EMPNO6))
                    {
                        concast.Append(" AND EMPNO6=:EMPNO6 ");
                        hashtable.Add(":EMPNO6", obj.EMPNO6);
                    }

                    if (!String.IsNullOrEmpty(obj.ADNO))
                    {
                        concast.Append(" AND ADNO=:ADNO ");
                        hashtable.Add(":ADNO", obj.ADNO);
                    }

                    if (!String.IsNullOrEmpty(obj.USRNAME))
                    {
                        concast.Append(" AND USRNAME=:USRNAME ");
                        hashtable.Add(":USRNAME", obj.USRNAME);
                    }

                }
                sql = System.String.Format(@" DELETE FROM CONV_USER ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/